<%--
  Created by IntelliJ IDEA.
  User: Jun
  Date: 2018/8/16
  Time: 11:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="pu" uri="http://pageUtil.cn/common/" %>
<%@ page trimDirectiveWhitespaces="true" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ page import="cv.gzd.robot.pojo.User" %>
<%
    User user= (User) session.getAttribute("USER_SESSION");
%>
<html>
<head>
    <meta charset="UTF-8">
    <title>设备控制</title>
    <!-- Bootstrap Core CSS -->
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="${pageContext.request.contextPath}/css/metisMenu.min.css" rel="stylesheet">

    <!-- DataTables CSS -->
    <link href="${pageContext.request.contextPath}/css/dataTables.bootstrap.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="${pageContext.request.contextPath}/css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="${pageContext.request.contextPath}/css/font-awesome.min.css" rel="stylesheet"
          type="text/css">
    <link href="${pageContext.request.contextPath}/css/boot-crm.css" rel="stylesheet"
          type="text/css">

    <!--<script-->
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <script type="text/javascript">
        window.onload = function () {
            var height = $(window).height();
            $("#wrapper").css("height", height);
        }
    </script>
</head>
<body>
<div id="wrapper" style="background-color:#000000;">
    <!-- Navigation -->
    <nav class="navbar navbar-default navbar-static-top" role="navigation"
         style="margin-bottom: 0;background-color: #01C9E2">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse"
                    data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span> <span
                    class="icon-bar"></span> <span class="icon-bar"></span> <span
                    class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/index.action">IRIM后端控制管理系统</a>
        </div>

        <ul class="nav navbar-top-links navbar-right">
            <li>
                <ul><%=user.getRealname()%><%=user.getAuthorization()%>,你好!</ul>
            </li>
            <li class="dropdown"><a class="dropdown-toggle"
                                    data-toggle="dropdown" href="#"> <i class="fa fa-user fa-fw"></i>
                <i class="fa fa-caret-down"></i>
            </a>
                <ul class="dropdown-menu dropdown-user">
                    <li><a href="#" data-toggle="modal" data-target="#PswdSaveDialog"><i
                            class="fa fa-user fa-fw"></i> 修改密码</a></li>
                    <li class="divider"></li>
                    <li><a href="/logout"><i class="fa fa-sign-out fa-fw"></i>
                        退出登录</a></li>
                </ul> <!-- /.dropdown-User --></li>
        </ul>

    </nav>
    <div class="navdiv collapse navbar-collapse"  >
        <ul class="nav navbar-nav ">
            <li class="">
                <div><a href="/index.action"><span class="icon fa fa-gamepad"></span>状态和控制</a></div>
            </li>
            <li class="">
                <div><a href="/log/list.action"><span class="icon fa fa-wpforms"></span> 运行日志</a></div>
            </li>
            <li class="">
                <div><a href="/dev/list.action"><span class="icon fa fa-desktop"></span>设备管理</a></div>
            </li>
            <li class="">
                <div><a href="/user/list.action"><span class="icon fa fa-users"></span>用户管理</a></div>
            </li>
        </ul>
    </div>

    <div class="panel panel-default page-wapper">
        <div class=" headingcolor">
            <button type="button" class="addStyle btn btn-primary  " data-toggle="modal"
                    data-target="#DevSaveDialog">新增设备</button>
            <form class="form-inline" action="${pageContext.request.contextPath }/dev/list.action"
                  method="post">
                <div class="form-group">
                    <label for="customerFrom">类别</label>
                    <select class="form-control" id="customerFrom" placeholder="类别" name="QueryType">
                        <option value="">--请选择--</option>
                        <option value="robotname">机器人名字</option>
                        <option value="model">机器人型号</option>
                        <option value="robotIp">机器人IP</option>
                    </select>
                    <input type="text" class="form-control" id="robotValue" value="${robotValue}" name="robotValue">
                </div>


                <button type="submit" class="btn btn-primary">查询</button>
            </form>
        </div>


        <div class="panel-body">
            <div class="row">
                <div class="col-lg-12">
                    <table class="table table-bordered table-striped tablestyle">
                        <thead class="thcolor">
                        <tr>
                            <th>序号</th>
                            <th>机器人名字</th>
                            <th>机器人型号</th>
                            <th>机器人IP</th>
                            <th>端口号</th>
                            <th>操作</th>
                            <th>控制</th>
                        </tr>
                        </thead>
                        <tbody>

                        <c:forEach items="${page.rows}" var="row">
                            <tr>
                                <td>${row.rid}</td>
                                <td>${row.robotname}</td>
                                <td>${row.model}</td>
                                <td>${row.robotIp}</td>
                                <td>${row.robotport}</td>
                                <td>
                                    <a href="#" class="btn btn-primary btn-xs" data-toggle="modal"
                                       data-target="#DevEditDialog" onclick="editDev(${row.rid})">修改</a>
                                    <a href="#" class="btn btn-danger btn-xs"
                                       onclick="deleteDev(${row.rid})">删除</a>
                                </td>
                                <td>
                                    <a href="#" class="btn btn-primary btn-xs" data-toggle="modal"
                                       data-target="#customerEditDialog" onclick="devcontect(${row.rid})">连接</a>
                                    <a href="#" class="btn btn-danger btn-xs" onclick="devdiscontect(${row.rid})">断开</a>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                    <div class="col-md-12 text-right">
                        <pu:page url="${pageContext.request.contextPath }/dev/list.action"/>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
<!--表格-->

<!--编辑界面-->
<div class="modal fade" id="DevEditDialog" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="EditDevLabel">修改用户</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="edit_Dev_form">
                    <input type="hidden" id="edit_Rid" name="rid"/>
                    <div class="form-group">
                        <label for="edit_Robotname" class="col-sm-2 control-label">机器人名字</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="edit_Robotname" placeholder="机器人名字"
                                   name="robotname">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="edit_Model" class="col-sm-2 control-label">机器人型号</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="edit_Model" placeholder="机器人型号"
                                   name="model">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="edit_RobotIp" class="col-sm-2 control-label">机器人IP</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="edit_RobotIp" placeholder="机器人IP"
                                   name="robotIp">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="edit_Robotport" class="col-sm-2 control-label">机器人端口</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="edit_Robotport" placeholder="机器人端口"
                                   name="robotport">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="updateDev()">保存修改</button>
            </div>
        </div>
    </div>
</div>
<!-- /#wrapper -->
<%--新增界面--%>
<div class="modal fade" id="DevSaveDialog" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="SaveDevLabel">新增用户</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="save_Dev_form">
                    <input type="hidden" id="save_Rid" name="rid"/>
                    <div class="form-group">
                        <label for="save_Robotname" class="col-sm-2 control-label">机器人名字</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="save_Robotname" placeholder="机器人名字"
                                   name="robotname">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="save_Model" class="col-sm-2 control-label">机器人型号</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="save_Model" placeholder="机器人型号"
                                   name="model">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="save_RobotIp" class="col-sm-2 control-label">机器人IP</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="save_RobotIp" placeholder="机器人IP"
                                   name="robotIp">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="save_Robotport" class="col-sm-2 control-label">机器人端口</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="save_Robotport" placeholder="机器人端口"
                                   name="robotport">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="insertDev()">保存</button>
            </div>
        </div>
    </div>
</div>
<!--底部-->
</div>
<%--修改密码--%>
<div class="modal fade" id="PswdSaveDialog" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="SavePswd">修改密码</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="save_Pswd_form">
                    <input type="hidden" id="edit_Pswd_Uid" name="uid" value="<%=user.getUid()%>"/>
                    <div class="form-group">
                        <label for="edit_Pswd_new" class="col-sm-2 control-label">新密码</label>
                        <div class="col-sm-10">
                            <input type="password" class="form-control" id="edit_Pswd_new" placeholder="新密码"
                                   name="password">
                        </div>
                        <label for="edit_Pswd_again" class="col-sm-2 control-label">再次输入新密码</label>
                        <div class="col-sm-10">
                            <input type="password" class="form-control" id="edit_Pswd_again" placeholder="再次输入新密码"
                                   name="pwsd">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="updatePswd()">保存修改</button>
            </div>
        </div>
    </div>
</div>
<!-- jQuery -->
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>

<!-- Metis Menu Plugin JavaScript -->
<script src="${pageContext.request.contextPath}/js/metisMenu.min.js"></script>

<%--DataTables JavaScript--%>

<script src="${pageContext.request.contextPath}/js/jquery.dataTables.min.js"></script>
<script src="${pageContext.request.contextPath}/js/dataTables.bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="${pageContext.request.contextPath}/js/sb-admin-2.js"></script>

<script type="text/javascript">
    function editDev(id) {
        $.ajax({
            type: "get",
            url: "${pageContext.request.contextPath}/dev/edit.action",
            data: {"id": id},
            success: function (data) {
                $("#edit_Rid").val(data.rid);
                $("#edit_Robotname").val(data.robotname);
                $("#edit_Model").val(data.model);
                $("#edit_RobotIp").val(data.robotIp);
                $("#edit_Robotport").val(data.robotport);
            }
        });
    }
    function insertDev() {
        $.post("${pageContext.request.contextPath}/dev/save.action", $("#save_Dev_form").serialize(), function (data) {
            if(data.code==801){
                alert("设备信息添加成功！");
                window.location.reload();
            }
        });
    }

    function updateDev() {
        $.post("${pageContext.request.contextPath}/dev/update.action", $("#edit_Dev_form").serialize(), function (data) {
            if(data.code==801){
                alert("设备信息更新成功！");
                window.location.reload();
            }
        });
    }

    function deleteDev(id) {
        if (confirm('确实要删除该设备吗?')) {
            $.post("${pageContext.request.contextPath}/dev/delete.action", {"id": id}, function (data) {
                if(data.code==801){
                    alert("设备删除更新成功！");
                    window.location.reload();
                }
            });
        }
    }
    function devcontect(id) {
        if (confirm('确实要连接该设备吗?')) {
            $.post("${pageContext.request.contextPath}/dev/contect.aciton", {"id": id}, function (data) {
                alert("设备连接成功!");
                window.location.reload();
                <%--window.location.href="${pageContext.request.contextPath}/index.action";--%>
            });
        }
    }
    function devdiscontect(id) {
        if (confirm('确实要断开该设备吗?')) {
            $.post("${pageContext.request.contextPath}/dev/discontect.aciton", {"id": id}, function (data) {
                alert("设备断开成功！");
                window.location.reload();
            });
        }
    }
    function updatePswd() {
        $.post("${pageContext.request.contextPath}/user/updatepswd.action", $("#save_Pswd_form").serialize(), function (data) {
            if (data.code==801){
                alert("修改密码成功！");
                window.location.reload();
            }
            if(data.code==802){
                alert("两次密码不一致！");
                window.location.reload();
            }
        });
    }
</script>

</body>

</html>